<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wh__ishotelhomestay">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.name"
            placeholder="车辆名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.corporateName"
            placeholder="公司名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.endurance"
            placeholder="续航(≥KM)"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.price"
            placeholder="每日租金(≤元)"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('admin:rentalcarelectrocar:save')"
            type="primary"
            @click="addOrUpdateHandle()"
            >{{ $t("add") }}</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('admin:rentalcarelectrocar:delete')"
            type="danger"
            @click="deleteHandle()"
            >{{ $t("deleteBatch") }}</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%"
        :height="he"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="pic"
          label="车辆图片"
          header-align="center"
          align="center"
          width="200"
        >
          <template slot-scope="scope">
            <img :src="scope.row.pic" style="width: 100px; height: 100px" />
          </template>
        </el-table-column>
        <el-table-column
          prop="name"
          label="车辆名称"
          header-align="center"
          align="center"
          width="160"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="corporateName"
          label="所属公司"
          header-align="center"
          align="center"
          width="160"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="electromobilePower"
          label="电瓶功率"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="endurance"
          label="续航"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.endurance }}KM</template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="每日租金(元)"
          header-align="center"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="latitude"
          label="是否投保"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.insureType == 0 ? "已投保" : "未投保" }}
          </template>
        </el-table-column>
        <el-table-column
          prop="depositType"
          label="押金(元)"
          header-align="center"
          align="center"
          width="120"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            {{ depositTypeCfg[scope.row.depositType] }}
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPermission('admin:rentalcarelectrocar:update')"
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
              >{{ $t("update") }}</el-button
            >
            <el-button type="text" size="small" @click="viewHandle(scope.row)"
              >查看</el-button
            >
            <el-button
              v-if="$hasPermission('admin:rentalcarelectrocar:delete')"
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        :disabled="disabled"
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
        @changeDisabled="disabled = false"
      ></add-or-update>
    </div>
  </el-card>
</template>
  
  <script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./electrocar-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      he:'auto',
      disabled: false,
      depositTypeCfg: {
        0: "芝麻免押金",
        1: "500",
        2: "1000",
        3: "1500",
        4: "2000",
      },
      mixinViewModuleOptions: {
        getDataListURL: "/travel/travel/rentalcarelectromobile/page",
        getDataListIsPage: true,
        deleteURL: "/travel/travel/rentalcarelectromobile",
        deleteIsBatch: true,
      },
      dataForm: {},
    };
  },
  watch: {
    dataList(newval, oldval) {
      if (newval != oldval) {
        this.he = "auto";
        setTimeout(() => {
          this.he = "calc(100vh - 270px)";
        }, 500);
      }
    },
    "dataForm.status": {
      immediate: true,
      deep: true,
      handler(newValue) {},
    },
  },
  components: {
    AddOrUpdate,
  },
  created() {
    this.$http
      .get("/travel/travel/rentalcarelectromobile/page", {
        params: {
          page: 1,
          limit: 10,
        },
      })
      .then(({ data: res }) => {});
  },
  methods: {
    viewHandle(row) {
      this.addOrUpdateVisible = true;
      this.disabled = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.visible = true;

        this.$refs.addOrUpdate.dataForm.id = row.id;
        this.$refs.addOrUpdate.dataForm.details = true;
        this.$refs.addOrUpdate.init();
      });
    },
  },
};
</script>
  